//
//  FeedBackTool.m
//  AFNnetworking
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 mjh. All rights reserved.
//

#import "FeedBackTool.h"

@interface FeedBackTool ()

@end

@implementation FeedBackTool

+ (void)sendFeedbackMail:(NSString *)mail delegate:(id<MFMailComposeViewControllerDelegate>)mydelegate viewcontroller:(UIViewController *)controller{
    Class mailClass = NSClassFromString(@"MFMailComposeViewController");
    if (mailClass != nil) {
        if ([mailClass canSendMail]) {
            //
            [self displayMailBox:mail delegate:mydelegate viewcontroller:controller];
        }
        else{
            //打开设备自带的邮箱工具
            [self showMailBoxOnDevice];
        }
    }
    else{
        //打开设备自带的邮箱工具
        [self showMailBoxOnDevice];
    }

}

//打开设备自带的邮箱工具
+ (void)showMailBoxOnDevice{
    NSString *mail = @"mailto:1434279720@qq.com";
    mail = [mail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:mail]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mail]];
}

// 创建 并携带编辑好的邮件内容 模态进入邮件视图
+ (void)displayMailBox:(NSString *)mail delegate:(id<MFMailComposeViewControllerDelegate>)mydelegate viewcontroller:(UIViewController *)controller{
    ///创建邮件视图
    MFMailComposeViewController *mailBox = [[MFMailComposeViewController alloc] init];
    //填写收件人地址
    NSArray *recipient = [NSArray arrayWithObjects:@"1434279720@qq.com", nil];
    [mailBox setToRecipients:recipient];
    // 填写主题
    [mailBox setSubject:@"意见反馈"];
    // 填写内容
    NSString *message = mail;
    [mailBox setMessageBody:message isHTML:YES];
    //    //添加一个文件
    //    UIImage *image = [UIImage imageNamed:@"gzj.jpg"];
    //    NSData *data = UIImagePNGRepresentation(image);
    //    [mailBox addAttachmentData:data mimeType:@"" fileName:@"随便填.jpg"];
    
    //设置代理人
    mailBox.mailComposeDelegate = mydelegate;
    
    [controller presentViewController:mailBox animated:YES completion:^{
    }];
    
    
}

@end
